package com.jie.myvhr.controller;

import com.jie.myvhr.bean.Hr;
import com.jie.myvhr.bean.MsgContent;
import com.jie.myvhr.bean.RespBean;
import com.jie.myvhr.bean.SysMsg;
import com.jie.myvhr.service.HrService;
import com.jie.myvhr.service.SysMsgService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @date 2019/6/29 -15:20
 */
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private HrService hrService;

    @Resource
    private SysMsgService sysMsgService;


    /**
     * 查询除当前用户外的所有用户列表
     */
    @RequestMapping(value = "/hrs", method = RequestMethod.GET)
    public List<Hr> getAllHr() {
        return hrService.getAllHrExceptAdmin();
    }

    @RequestMapping("/sysmsgs")
    public List<SysMsg> getSysmsg(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                  @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return sysMsgService.getSysMsgByPage(page, size);
    }

    /**
     * 发送系统消息
     */
    @RequestMapping(value = "/nf", method = RequestMethod.POST)
    public RespBean sendNf(MsgContent msg) {
        if (sysMsgService.sendMsg(msg)) {
            return RespBean.ok("发送成功!");
        }
        return RespBean.error("发送失败!");
    }
}
